package lxy.contacttest;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.EditText;

import java.util.ArrayList;
import java.util.List;

import lxy.contacttest.utils.ContactBean;
import lxy.contacttest.utils.EmailBean;
import lxy.contacttest.utils.PhoneBean;
import lxy.contacttest.utils.PhoneContactUtils;

/**
 * Created by dengdayi
 * Date: 2016/05/31 12：04
 * 增加联系人页面
 */
public class ContactAddActivity extends AppCompatActivity {

    private EditText mEtName;
    private EditText mEtPhone;
    private EditText mEtEmail;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);
        mEtName = (EditText) findViewById(R.id.et_name);
        mEtPhone = (EditText) findViewById(R.id.et_mobile);
        mEtEmail = (EditText) findViewById(R.id.et_email);
    }


    public void doSave(View view) {
        String name = mEtName.getText().toString().replaceAll(" ", "");
        String phone = mEtPhone.getText().toString().replaceAll(" ", "");
        String email = mEtEmail.getText().toString().replaceAll(" ", "");

        List<PhoneBean> phoneBeans = new ArrayList<>();
        phoneBeans.add(new PhoneBean(phone));

        List<EmailBean> emailBeans = new ArrayList<>();
        emailBeans.add(new EmailBean(email));
        ContactBean contactBean = new ContactBean(name, phoneBeans, emailBeans);

        PhoneContactUtils.addContacts(this, contactBean, -1);
        setResult(RESULT_OK);
        finish();
    }
}
